package servlet.PropertyManagementModule.complaintRecord;

import bean.dto.EquipmentPage;
import bean.pojo.ComplaintRecord;
import bean.pojo.Maintenance;
import com.alibaba.fastjson2.JSONObject;
import commons.baseServlet.BaseServlet;
import commons.format.NumberFormat;
import commons.r.R;
import service.ComplaintRecordService;
import service.EquipmentMaintenanceService;
import service.impl.ComplaintRecordServiceImpl;
import service.impl.EquipmentMaintenanceServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * servlet.PropertyManagementModule.complaintRecord
 * User: xlh
 * Date: 2024/12/21 15:25
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(value = "/complaintRecord/*")
public class ComplaintRecordServlet  extends BaseServlet {
    public R findByPage(HttpServletRequest request){
        Integer page= NumberFormat.stringToInteger(request.getParameter("page"));
        Integer limit= NumberFormat.stringToInteger(request.getParameter("limit"));
        String selectMonth= request.getParameter("selectMonth");
        String selectedStatus= request.getParameter("selectedStatus");
        ComplaintRecordService complaintRecordService=new ComplaintRecordServiceImpl();
        EquipmentPage equipmentPage=new EquipmentPage();
        //查询与维修一样。
        equipmentPage.setSelectMonth(selectMonth);
        equipmentPage.setSelectedStatus(selectedStatus);
        equipmentPage.setPage(page);
        equipmentPage.setLimit(limit);

        List<ComplaintRecord> list = null;
        Long  total=complaintRecordService.findByTotal(equipmentPage);
        //当前页码的数据
        if(total>0) {
            //当前页码的数据
            list =complaintRecordService.findByPage(equipmentPage);
        }
        R r= R.ok().addData("total",total).addData("list",list);
        return r;
    }
    public R updatComplaintRecord(HttpServletRequest request){
        try {
            BufferedReader bufferedReader=request.getReader();
            String data=bufferedReader.readLine();
            ComplaintRecord complaintRecord= JSONObject.parseObject(data,ComplaintRecord.class);
            ComplaintRecordService complaintRecordService=new ComplaintRecordServiceImpl();
            boolean t=complaintRecordService.updatComplaintRecord(complaintRecord);
            return t?R.ok("修改成功"):R.ok("修改失败");
        } catch (
                IOException e) {
            e.printStackTrace();
        }
        return R.error("添加出错");
    }
}

